package cn.seecoder.ai.controller;

import cn.seecoder.ai.model.vo.MachineLearningPipelineVO;
import cn.seecoder.ai.model.vo.ModelVO;
import cn.seecoder.ai.model.vo.ResultVO;
import cn.seecoder.ai.service.MachineLearningPipelineService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DingXiaoyu
 * @date 2023/4/12 15:10
 */
@Slf4j
@RestController
@RequestMapping("${apiPrefix}/ml/pipelines")
public class MachineLearningPipelineController {

    @Autowired
    MachineLearningPipelineService machineLearningPipelineService;

    @ApiOperation("增加流水线")
    @PostMapping
    public ResultVO<MachineLearningPipelineVO> addPipeline(@RequestBody MachineLearningPipelineVO machineLearningPipelineVO){
        return ResultVO.buildSuccess(machineLearningPipelineService.addPipeline(machineLearningPipelineVO));
    }

    @ApiOperation("使用流水线")
    @PostMapping("/{pipelineId}")
    public ResultVO<ModelVO> usePipeline(@PathVariable(value = "pipelineId") Integer pipelineId,
                                         @RequestParam(value = "fileId") Integer fileId,
                                         @RequestParam(value = "modelName")String modelName){
        return ResultVO.buildSuccess(machineLearningPipelineService.usePipeline(pipelineId,fileId,modelName));
    }

    @ApiOperation("查看用户所有流水线")
    @GetMapping
    public ResultVO<List<MachineLearningPipelineVO>> findPipelines(@RequestParam(value = "userId") Integer userId){
        return ResultVO.buildSuccess(machineLearningPipelineService.findPipelines(userId));
    }

    @ApiOperation("删除流水线")
    @DeleteMapping("/{pipelineId}")
    public ResultVO<Boolean> deletePipeline(@PathVariable(value = "pipelineId") Integer pipelineId){
        return ResultVO.buildSuccess(machineLearningPipelineService.deletePipeline(pipelineId));
    }
}
